<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>北京航天公司固定资产管理系统</title>
</head>
<script type="text/javascript" src="/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="/layui/layui.js"></script>
<link rel="stylesheet" href="/layui/css/layui.css">
<body>
<i style="font-size:50px; color: black" class="layui-icon layui-icon-location">维修申请</i>
<form class="layui-form">
    <input type="text" name="photo" id="btn3" hidden>
    <div class="layui-collapse">
        <div class="layui-colla-item">

            <div class="layui-form-item">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">故障信息</h2>
                    <div class="layui-colla-content layui-show">

                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label" style="text-align:left ">故障类型</label>
                            <div class="layui-input-block">
                                <div>
                                    <input type="checkbox" name="faultId" th:each="list : ${FaulttypeList}" th:value="${list.id}"
                                           th:title="${list.faultname}">
                                </div>
                            </div>
                            <br><br>

                            <div class="layui-form-item">
                                <label class="layui-form-label" style="text-align:left ">图像</label>
                                <div class="layui-input-block">
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="test2">图片上传</button>
                                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                            预览图：
                                            <div class="layui-upload-list" id="demo2"></div>
                                        </blockquote>
                                    </div>
                                    <!--<button type="button"  class="layui-btn" id="test1">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>-->
                                    <text style="color: #bfbebe">请上传.jpg .png .gif .bmp .jpeg格式，不超过10M的图片</text>
                                    </td>
                                </div>
                            </div>

                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label" style="text-align:left ">故障备注</label>
                                <div class="layui-input-block">
                                <textarea name="scrapDescription" placeholder="请简单叙述下资产的损坏情况"
                                          class="layui-textarea"></textarea>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>

            <h2 class="layui-colla-title">资产信息</h2>
            <div class="layui-colla-content layui-show">

                <div class="layui-form-item">
                    <label class="layui-form-label">资产现归属</label>
                    <div class="layui-input-inline">
                        <select name="organisation" id="organisation" lay-filter="mySelect">
                            <option value="0" selected>所属组织</option>
                        </select>
                    </div>

                    <div class="layui-input-inline">
                        <select name="department" id="department">
                            <option value="0" selected>所属部门/门店</option>
                        </select>
                    </div>

                    <div class="layui-input-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="responsible" placeholder="责任人" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">资产编号</label>
                    <div class="layui-input-inline">
                        <input type="text" id="propertyId" name="propertyId" placeholder="请输入资产编号" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">报修 申请人</label>
                    <div class="layui-input-inline">
                        <input type="text" name="scrapOperator" placeholder="请输入申请人姓名" class="layui-input">
                    </div>
                </div>
            </div>


            </div>
        </div>
    </div>
    <br><br>

</form>
<button class="layui-btn" type="button" onclick="javascript:addd()">立即提交</button>
<button class="layui-btn" onclick="insertMaintain()">返回</button>
</body>

<script type="text/javascript">

    $(function () {
        //初始化所在组织下拉框
        organisation();

        $("#propertyId").change(function () {
            var propertyId = $("#propertyId").val();

            $.post("/scrap/exist?property_id=" + propertyId, function (res) {

                if (res.coud != 200) {
                    alert(res.msg)
                }

            }, "json")
        })
    })

    //处理表单下拉框
    function organisation() {
        layui.use("form", function () {
            var form = layui.form;

            //所在组织下拉框
            $.get("/scrap/organisation?id=" + 0, function (result) {
                // console.log(result);
                for (var i = 0; i < result.length; i++) {
                    //console.log(result[i].dname)
                    $("[name='organisation']").append("<option value='" + result[i].did + "'>" + result[i].dname + "</option>");
                }
                form.render('select');
            }, "json");

            //监控lay-filter=mySelect的下拉框事件  //所在部门下拉框
            form.on('select(mySelect)', function (object) {
                $("#department option:gt(0)").remove();
                var id = $("#organisation").val()
                // console.log(id);
                $.get('/scrap/organisation?id=' + id, function (res) {
                    // console.log(res);
                    for (var i = 0; i < res.length; i++) {
                        $("#department").append('<option value="' + res[i].did + '">' + res[i].dname + '</option>')
                    }
                    form.render('select');
                }, "json")
            })

        })
    }

    layui.use(['upload', 'element'], function () {
        var upload = layui.upload;
        //注意：折叠面板 依赖 element 模块，否则无法进行功能性操作
        var element = layui.element;

        //多图片上传
        upload.render({
            elem: '#test2'
            , url: "/scrap/filesUpload"
            , multiple: true,
            drag: false,//是否接受拖拽的文件上传
            size: 10240, //最大可允许上传的大小，单位 KB
            /*auto: false,
            bindAction: '#btn1',//指向一个按钮触发上传*/
            choose: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    /* console.log(index); //得到文件索引
                     console.log(file); //得到文件对象
                     console.log(result); //得到文件base64编码，比如图片*/
                    $("#nihao").val(result);
                    $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img"  height="140" width="200"/>')
                });
            }
            , done: function (res) {
                $("#btn3").val(res.url);
            }
            , error: function (res) {
                //请求异常回调
                alert(res.msg);
            }
        });

    });

    //添加维修申请
    function addd() {
        var dataForm = $("form").serialize();
        console.log(dataForm)
        $.post("/scrap/addMaintain?" + dataForm, function (data) {
            alert(data.msg);
            window.location.href = "/jump/goScrapIndex";
        }, "json")
    }

    //返回维修单页面
    function insertMaintain() {
        location.href = "/jump/goScrapIndex"
    }

</script>

</html>

